﻿using System.Diagnostics;
using System.Windows.Forms;

namespace MetaView.Module.Demo;

public class DemoModule : AppModuleBase
{
    public override ModuleDescription Description { get; }
    public DemoModule()
    {
        this.Description = new ModuleDescription("D7F3274A-2526-43FD-B278-099630BDA33E", "Demo", new Version(1, 0, 0, 0), "PAN", "这是一个测试插件");
    }

    protected override Task OnInitializeAsync(IApplication application, AppModuleInitEventArgs e)
    {
        var form = new Form();
        return Task.CompletedTask;
    }

    protected override async Task OnStartupAsync(IApplication application, AppModuleStartupEventArgs e)
    {
        //wpf中
        //var resourceService = this.ServiceProvider.GetRequiredService<IResourceService>();

        //resourceService.AddResourceDictionary(new ResourceDictionary());

        //Debug.WriteLine("线程Id" + Thread.CurrentThread.ManagedThreadId);

        //await Task.Delay(1000);

        //await Task.Run(async () =>
        //{
        //    for (var i = 0; i < 10; i++)
        //    {
        //        Debug.WriteLine("这里是线程池线程执行" + Thread.CurrentThread.ManagedThreadId);
        //    }
        //    using (var tokenSource = new CancellationTokenSource(2000))
        //    {
        //        //await Task.Delay(3000);

        //        try
        //        {
        //            await MainThreadTaskFactory.SwitchToMainThreadAsync(tokenSource.Token);

        //            Debug.WriteLine("这里是主线程执行" + Thread.CurrentThread.ManagedThreadId);

        //            await MainThreadTaskFactory.ReleaseMainThreadAsync();
        //            Debug.WriteLine("主线程之后执行" + Thread.CurrentThread.ManagedThreadId);
        //        }
        //        catch (Exception)
        //        {


        //        }

        //    }

        //});


        System.Windows.MessageBox.Show("Hello 模块已加载");
    }
}